package com.edu.tool.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.tool.service.BaseService;
import com.edu.tool.util.AppBaseMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public abstract class  SysBaseServiceImpl<T,M extends AppBaseMapper<T>> implements BaseService<T> {
    @Autowired
    protected M mapper;

    @Override
    @Transactional(propagation= Propagation.NOT_SUPPORTED)
    public T getObjectById(Integer id){
        return mapper.selectById(id);
    }

    @Override
    @Transactional(propagation=Propagation.NOT_SUPPORTED)
    public List<T> getObjectList(){
        return mapper.selectList(null);
    }


    public Integer delete(Integer id){
        return mapper.deleteById(id);
    }

    @Override
    public Integer update(T object){
        return mapper.updateById(object);
    }


    @Override
    public Integer add(T object){
        return mapper.insert(object);
    }

    @Override
    @Transactional(propagation=Propagation.NOT_SUPPORTED)
    public IPage<T> findItemByPage(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】

        Page<T> page = new Page<T>(currentPage.longValue(),pageSize.longValue());

        IPage<T> list = mapper.selectPage(page,null);
        return list;

    }

//    @Override
//    public IPage<T> findItemByPage(Long currentPage, Long pageSize) {
//        Page<T> page = new Page<T>(currentPage,pageSize);
//
//        IPage<T> pagedata = mapper.selectPage(page, null);
//        return pagedata;
//    }

 


}
